package com.seatademo.orders.service.impl;

import com.seatademo.orders.entity.OrderTbl;
import com.seatademo.orders.feign.OrderTblFeign;
import com.seatademo.orders.mapper.OrderTblMapper;
import com.seatademo.orders.service.IOrderTblService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangjiacang
 * @since 2021-09-02
 */
@Service
public class OrderTblServiceImpl extends ServiceImpl<OrderTblMapper, OrderTbl> implements IOrderTblService {

    @Autowired
    private OrderTblFeign orderTblFeign;

    @Override
    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    public OrderTbl create() {
        //订单操作
        OrderTbl orderTbl = new OrderTbl();
        orderTbl.setUserId("1");
        orderTbl.setMoney(100);
        //保存订单
        baseMapper.insert(orderTbl);
        //int i=1/0; //模拟异常
        //减少用户金额
        orderTblFeign.debit();
        return orderTbl;
    }
}
